/*
 * RawDataView.cpp
 *
 *  Created on: Jan 29, 2013
 *      Author: johnny
 */

#include "RawDataView.h"

#ifdef WIN32
#define OUTPUT_FILE "C:\\rawdataviewlog.log"
#else
#define OUTPUT_FILE "/home/johnny/rawdataview.log"
#endif

RawDataView::~RawDataView() {
    if(output.is_open())
        output.close();
}

void RawDataView::init() {
    output.open(OUTPUT_FILE);
    if(!output.is_open())
        add2Log(core::Error, "Failed to open output file");
}

void RawDataView::draw() {

}

void RawDataView::validateData(const core::DataPackage &pkg) {
	if(!output.is_open())
		return;

    // write pkg to file

    output << "CycleID " << static_cast<int>(pkg.cycleID) << std::endl;
    output << "CycleCnt " << static_cast<int>(pkg.cycleCnt) << std::endl;
    output << "Timestamp " << pkg.timestamp << std::endl;
    
    output << "data: ";
    for(unsigned int i = 0; i < pkg.dataLength; ++i) {
        output << static_cast<unsigned int>(pkg.data[i]);
    }
    output << std::endl << std::endl;
}
